package com.ruoyi.slope.video.crack.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.video.crack.domain.SlopeSurfaceCrackMonitor;
import com.ruoyi.slope.video.crack.service.ISlopeSurfaceCrackMonitorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地表裂缝监测Controller
 * 
 * @author ruoyi
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/video/crack")
public class SlopeSurfaceCrackMonitorController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeSurfaceCrackMonitorService slopeSurfaceCrackMonitorService;

    /**
     * 查询地表裂缝监测列表
     */
    @PreAuthorize("@ss.hasPermi('video:crack:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeSurfaceCrackMonitor slopeSurfaceCrackMonitor)
    {
        startPage();
        List<SlopeSurfaceCrackMonitor> list = slopeSurfaceCrackMonitorService.selectSlopeSurfaceCrackMonitorList(slopeSurfaceCrackMonitor);
        return getDataTable(list);
    }

    /**
     * 导出地表裂缝监测列表
     */
    @PreAuthorize("@ss.hasPermi('video:crack:export')")
    @Log(title = "地表裂缝监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeSurfaceCrackMonitor slopeSurfaceCrackMonitor)
    {
        List<SlopeSurfaceCrackMonitor> list = slopeSurfaceCrackMonitorService.selectSlopeSurfaceCrackMonitorList(slopeSurfaceCrackMonitor);
        ExcelUtil<SlopeSurfaceCrackMonitor> util = new ExcelUtil<SlopeSurfaceCrackMonitor>(SlopeSurfaceCrackMonitor.class);
        String path = util.exportExcel(response, list, "地表裂缝监测数据"); 
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取地表裂缝监测详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:crack:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeSurfaceCrackMonitorService.selectSlopeSurfaceCrackMonitorById(id));
    }

    /**
     * 新增地表裂缝监测
     */
    @PreAuthorize("@ss.hasPermi('video:crack:add')")
    @Log(title = "地表裂缝监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeSurfaceCrackMonitor slopeSurfaceCrackMonitor)
    {
        return toAjax(slopeSurfaceCrackMonitorService.insertSlopeSurfaceCrackMonitor(slopeSurfaceCrackMonitor));
    }

    /**
     * 修改地表裂缝监测
     */
    @PreAuthorize("@ss.hasPermi('video:crack:edit')")
    @Log(title = "地表裂缝监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeSurfaceCrackMonitor slopeSurfaceCrackMonitor)
    {
        return toAjax(slopeSurfaceCrackMonitorService.updateSlopeSurfaceCrackMonitor(slopeSurfaceCrackMonitor));
    }

    /**
     * 删除地表裂缝监测
     */
    @PreAuthorize("@ss.hasPermi('video:crack:remove')")
    @Log(title = "地表裂缝监测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeSurfaceCrackMonitorService.deleteSlopeSurfaceCrackMonitorByIds(ids));
    }
}
